package com.ule.merchant.order.mon.service.response;

import lombok.Data;

import java.io.Serializable;

/**
 * 处理返回结果
 */
@Data
public class ResultData<T> implements Serializable {

    //返回状态码
    private Integer code;
    //返回消息
    private String msg;
    //返回数据
    private T data;

    public ResultData() {
    }

    public ResultData(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    //成功
    public static <T> ResultData<T> success(T data) {
        ResultData<T> resultData = new ResultData<>();
        resultData.setCode(ResultCodeEnum.SUCCESS.getCode());
        resultData.setMsg(ResultCodeEnum.SUCCESS.getMsg());
        resultData.setData(data);
        return resultData;
    }

    //失败
    public static <T> ResultData<T> error(int code, String msg) {
        return new ResultData(code, msg);
    }

}
